package com.aidansmeaton.internet;

import java.util.ArrayList;

import android.util.Log;

public class PassengerNameValue {
	
	String[] horizontal_labels;
	String[] vertical_labels;
	float[] values;
	
	public PassengerNameValue(String source) {
		
		ArrayList<String> theNames = new ArrayList<String>();
		ArrayList<Float> theValues = new ArrayList<Float>();
		
		Log.w("PASSENGERS", source);
		
		int offset = source.indexOf("name=");
		int offset_end = source.indexOf("' value",offset);
		
		while (offset != -1){
			
			offset += 6;
			offset_end = offset + 14;
			theNames.add(source.substring(offset, offset_end));
			Log.w("DUM", source.substring(offset, offset_end));
			
			offset += 23;
			offset_end = source.indexOf("/>", offset) - 1;
			theValues.add(Float.parseFloat(source.substring(offset, offset_end)));
			
			offset = source.indexOf("name=",offset_end);
			offset_end = source.indexOf("' value",offset);
			
		}
		
		horizontal_labels = new String[theNames.size()];
		for (int i = 0; i < horizontal_labels.length; i++){
			horizontal_labels[i] = theNames.get(i).substring(5, 7);		// change 'Week 27 / 2005' to '27'
			Log.w("LABEL", horizontal_labels[i]);
		}
		
		float max = 0;
		values = new float[theValues.size()];
		for (int i = 0; i < horizontal_labels.length; i++){
			values[i] = theValues.get(i);
			if (values[i] > max){ max = values[i]; }
			Log.w("LABEL", "" + values[i]);
		}
		
		float half = max / 2;
		float quarter = half / 2;
		float three_quarters = half + quarter;
		vertical_labels = new String[] { Integer.toString((int)max) , Integer.toString((int)three_quarters), Integer.toString((int)half) , Integer.toString((int)quarter), "0" };
		
		
	}

	public String[] getVertical_labels() {
		return vertical_labels;
	}

	public void setVertical_labels(String[] vertical_labels) {
		this.vertical_labels = vertical_labels;
	}

	public String[] getHorizontal_labels() {
		return horizontal_labels;
	}

	public void setHorizontal_labels(String[] horizontal_labels) {
		this.horizontal_labels = horizontal_labels;
	}

	public float[] getValues() {
		return values;
	}

	public void setValues(float[] values) {
		this.values = values;
	}

}
